<?php
/**
 * Created by PhpStorm.
 * User: LiuJiaJun
 * Date: 2019/3/30
 * Time: 15:30
 */

namespace api\storage\service\client;


use api\storage\common\Constant;
use api\storage\model\ClientModel;
use api\storage\model\ClientVersionModel;

class JarClientService extends BaseClientService
{

    const JAR_TYPE = 3;
    /**
     * 认证socket客户端
     * 1. 根据code来查询uid再返回即可
     *
     * @param $code
     * @return mixed
     */
    public function authClient($code)
    {
        $clientModel = new ClientModel();
        $uid = $clientModel->queryUidByCode($code);
        return $uid;
    }

    public function initUploadLogRootPath($code)
    {
        $path = PUBLIC_PATH . Constant::LOG_JAR_PATH;
        $append = empty($code) ? '' : $code . '/';
        return $path . $append;
    }

    public function initVersionData($version)
    {
        $clientVersionModel = new ClientVersionModel();
        if (empty($version)) {
            return $clientVersionModel->queryLatestVersion(self::JAR_TYPE);
        }
        list($majorVersion, $minorVersion) = explode('.', $version);
        return $clientVersionModel->queryByVersion(self::JAR_TYPE, $majorVersion, $minorVersion);
    }


    public function initHistoryData()
    {
        $clientVersionModel = new ClientVersionModel();
        return $clientVersionModel->queryHistoryVersion(self::JAR_TYPE);
    }
}